package com.library.uiframework.utils;

import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;

/**
 * 在此写用途
 *
 * @author: zhiwei
 * @date: 2017-09-23 21:31
 * @version: 9.1.0
 */
public class ThreadUtils {
    public static final Handler MAIN_THREAD_HANDLER = new Handler(Looper.getMainLooper());
    private static String processName = "";

    public ThreadUtils() {
    }

    public static boolean isUIThread() {
        Looper mLooper = Looper.myLooper();
        return mLooper != null && mLooper == Looper.getMainLooper();
    }

    public static void throwIfUIThread() {
        if(isUIThread()) {
            throw new RuntimeException("u can not do this action in UI Thread!");
        }
    }
    
    public static Handler startHandlerThread(String threadName) {
        HandlerThread thread = new HandlerThread(threadName);
        thread.start();
        return new Handler(thread.getLooper());
    }
}
